package leetcode;

import java.util.Arrays;

public class Solution60 {
    private String res;
    private int count = 1;


    public static void main(String[] args) {
        String permutation = new Solution60().getPermutation(3, 3);
        System.out.println("permutation = " + permutation);
    }

    public String getPermutation(int n, int k) {
        recurse("", k, n, 0);
        return res;
    }

    public void recurse(String str, int k, int n, int index){
        if(count > k) return;
        if(index == n){
            System.out.println("str-----------" + str + ", count---------------" + count);
            if(count == k){
                res = str;
            }
            count++;
            return ;
        }

        for(int i = 1; i <= n; i++){
            if(str.indexOf("" + i) == -1){
                recurse(str + i, k, n, index + 1);
            }
        }
    }
}
